package com.ruoyi.jiajia.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaAppraise;
import com.ruoyi.system.service.IJiajiaAppraiseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评价Controller
 * 
 * @author knd
 * @date 2021-10-13
 */
@Controller
@RequestMapping("/jiajia/appraise")
public class JiajiaAppraiseController extends BaseController
{
    private String prefix = "jiajia/appraise";

    @Autowired
    private IJiajiaAppraiseService jiajiaAppraiseService;

    @RequiresPermissions("jiajia:appraise:view")
    @GetMapping()
    public String appraise()
    {
        return prefix + "/appraise";
    }

    /**
     * 查询评价列表
     */
    @RequiresPermissions("jiajia:appraise:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaAppraise jiajiaAppraise)
    {
        startPage();
        List<JiajiaAppraise> list = jiajiaAppraiseService.selectJiajiaAppraiseList(jiajiaAppraise);
        return getDataTable(list);
    }

    /**
     * 导出评价列表
     */
    @RequiresPermissions("jiajia:appraise:export")
    @Log(title = "评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaAppraise jiajiaAppraise)
    {
        List<JiajiaAppraise> list = jiajiaAppraiseService.selectJiajiaAppraiseList(jiajiaAppraise);
        ExcelUtil<JiajiaAppraise> util = new ExcelUtil<JiajiaAppraise>(JiajiaAppraise.class);
        return util.exportExcel(list, "评价数据");
    }

    /**
     * 新增评价
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存评价
     */
    @RequiresPermissions("jiajia:appraise:add")
    @Log(title = "评价", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaAppraise jiajiaAppraise)
    {
        return toAjax(jiajiaAppraiseService.insertJiajiaAppraise(jiajiaAppraise));
    }

    /**
     * 修改评价
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaAppraise jiajiaAppraise = jiajiaAppraiseService.selectJiajiaAppraiseById(id);
        mmap.put("jiajiaAppraise", jiajiaAppraise);
        return prefix + "/edit";
    }

    /**
     * 修改保存评价
     */
    @RequiresPermissions("jiajia:appraise:edit")
    @Log(title = "评价", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaAppraise jiajiaAppraise)
    {
        return toAjax(jiajiaAppraiseService.updateJiajiaAppraise(jiajiaAppraise));
    }

    /**
     * 删除评价
     */
    @RequiresPermissions("jiajia:appraise:remove")
    @Log(title = "评价", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaAppraiseService.deleteJiajiaAppraiseByIds(ids));
    }
}
